p_height=2;
p_width=12;

output_name="/Volumes/Data/gSVN/ethernet-switch/paper/figures/analytical_validation.eps"

my_dir="/Volumes/Data/gSVN/ethernet-switch/paper/plots/analytical_model_validation/";

loss_rate_mean_filename=paste(my_dir, "loss_rate_mean.txt", sep="");
loss_rate_std_filename=paste(my_dir, "loss_rate_std.txt", sep="");
AS_filename=paste(my_dir, "AS.txt", sep="");
loss_rate_mean_filename_3COM=paste(my_dir, "loss_rate_mean_3COM.txt", sep="");
loss_rate_std_filename_3COM=paste(my_dir, "loss_rate_std_3COM.txt", sep="");
loss_time_mean_filename_3COM=paste(my_dir, "loss_time_mean_3COM.txt", sep="");
loss_time_std_filename_3COM=paste(my_dir, "loss_time_std_3COM.txt", sep="");
loss_time_mean_filename_NG=paste(my_dir, "loss_time_mean_NG.txt", sep="");
loss_time_std_filename_NG=paste(my_dir, "loss_time_std_NG.txt", sep="");
tbl_mean_filename_3COM=paste(my_dir, "tbl_mean_3COM.txt", sep="");
tbl_std_filename_3COM=paste(my_dir, "tbl_std_3COM.txt", sep="");
tbl_mean_filename_NG=paste(my_dir, "tbl_mean_NG.txt", sep="");
tbl_std_filename_NG=paste(my_dir, "tbl_std_NG.txt", sep="");


loss_rate_mean=scan(file=loss_rate_mean_filename);
loss_rate_std=scan(file=loss_rate_std_filename);
loss_rate_mean_3COM=scan(file=loss_rate_mean_filename_3COM);
loss_rate_std_3COM=scan(file=loss_rate_std_filename_3COM);
AS=scan(file=AS_filename);
loss_time_mean_3COM=scan(file=loss_time_mean_filename_3COM);
loss_time_std_3COM=scan(file=loss_time_std_filename_3COM);
loss_time_mean_NG=scan(file=loss_time_mean_filename_NG);
loss_time_std_NG=scan(file=loss_time_std_filename_NG);
tbl_mean_3COM=scan(file=tbl_mean_filename_3COM);
tbl_std_3COM=scan(file=tbl_std_filename_3COM);
tbl_mean_NG=scan(file=tbl_mean_filename_NG);
tbl_std_NG=scan(file=tbl_std_filename_NG);

#quartz();
postscript(output_name, height=p_height, width=p_width, horizontal=FALSE, onefile=TRUE);

#The four numbers in the call to par are the number of lines of text reserved on the bottom, left, top and right, respectively, ps: text size, mpg: margin size for title, axis label and axis
saved_par=par(mar=c(2.5,2.5,0.3,0.1)+0.1, ps=10, mgp=c(1.5, 0.5,0), mfrow=c(1,3));

#plot for loss_rate
plotCI(x=AS, y=loss_rate_mean, uiw=loss_rate_std, col='blue', lty = 1, xlim = c(1100, 1900), ylim = c(0,1), gap = 0, type="b", ylab="Loss Rate", xlab="(a)", pch='+', cex=0.9);

plotCI(x=AS, y=loss_rate_mean_3COM, uiw=loss_rate_std_3COM, lty = 1, xaxt ="n", gap = 0, add = TRUE, col='red', pch='x', cex=0.9, type="b")

legend('topleft', legend=c('NetGear GS018', '3COM 3CGSU08'), col=c('blue', 'red'), pch=c('+', 'x'), bty='n');

#plot for loss time
y_lab=expression(paste("Time of Loss Episode(", mu, "s)", sep=""));

plotCI(x=AS, y=loss_time_mean_NG, uiw=loss_time_std_NG, col='blue', lty = 1, xlim = c(1100, 1900), ylim=c(0, 150), gap = 0, type="b", ylab=y_lab, xlab="Aggregated Sending Rate(Mb/s)   (b)", pch='+', cex=0.9);

plotCI(x=AS, y=loss_time_mean_3COM, uiw=loss_time_std_3COM, lty = 1, xaxt ="n", gap = 0, add = TRUE, col='red', pch='x', cex=0.9, type="b")

#legend('topleft', legend=c('NetGear GS018', '3COM 3CGSU08'), col=c('blue', 'red'), pch=c('+', 'x'), bty='n');

#plot for average time between loss
y_lab=expression((R[A]-R[S])~X~T[D]~(bit));

plotCI(x=AS, y=tbl_mean_NG, uiw=tbl_std_NG, col='blue', lty = 1, xlim = c(1100, 1900), ylim=c(0, 150000), gap = 0, type="b", ylab=y_lab,  xlab="(c)", pch='+', cex=0.9);

plotCI(x=AS, y=tbl_mean_3COM, uiw=tbl_std_3COM, lty = 1, xaxt ="n", gap = 0, add = TRUE, col='red', pch='x', cex=0.9, type="b")

#legend('topleft', legend=c('NetGear GS018', '3COM 3CGSU08'), col=c('blue', 'red'), pch=c('+', 'x'), bty='n');


par(saved_par);

dev.off()